package com.example.service.Impl;

import com.example.exception.CustomException;
import com.example.mapper.RoomImageMapper;
import com.example.pojo.RoomImage;
import com.example.service.RoomImageService;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class RoomImageServiceImpl implements RoomImageService {

    @Resource
    private RoomImageMapper roomImageMapper;

    /**
     * 添加房间图片
     *
     * @param roomImage
     */
    @Override
    public void add(RoomImage roomImage) {
        roomImageMapper.add(roomImage);
    }

    /**
     * 查询所有房间
     *
     * @return
     */
    @Override
    public List<RoomImage> selectAll(RoomImage roomImage) {
        List<RoomImage> list = roomImageMapper.selectAll(roomImage);
        return list;
    }

    /**
     * 根据id查询房间
     *
     * @param id
     * @return
     */
    @Override
    public   List<RoomImage>  selectById(Integer id) {
        List<RoomImage> list  = roomImageMapper.selectById(id);
        return list;
    }

    /**
     * 删除
     *
     * @param id
     */
    @Override
    public void deleteById(Integer id) {
        roomImageMapper.deleteById(id);
    }

    /**
     * 批量删除数据
     *
     * @param ids
     */
    @Override
    public void deleteBatch(List<Integer> ids) {
        for (Integer id:ids)
            roomImageMapper.deleteById(id);
    }

    /**
     * 修改房间图片
     *
     * @param roomImage
     */
    @Override
    public void updateById(RoomImage roomImage) {
        roomImageMapper.updateById(roomImage);
    }

    /**
     * 分页查询
     *
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public PageInfo<RoomImage> selectPage(RoomImage roomImage, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<RoomImage> list = roomImageMapper.selectAll(roomImage);
        return PageInfo.of(list);
    }
}
